<?php

namespace App\Containers\AppSection\Project\Actions;

use App\Containers\AppSection\File\Tasks\DownloadFileTask;
use App\Containers\AppSection\Project\Tasks\FindProjectByIdTask;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Requests\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;

class GetProjectAvatarAction extends Action
{
    public function run($id, Request $request): StreamedResponse
    {
        $project = app(FindProjectByIdTask::class)->run($id);

        if (empty($project->company->logo))
            throw new NotFoundException(__('ship::resource.not-found'));

        return app(DownloadFileTask::class)->run($project->company->logo->id);
    }
}
